﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DiArte.Data.Catalog
{
    public class LocalizedCategoryTextDal : BaseDal
    {
        /// <summary>
        /// Deletes all localized category texts
        /// </summary>
        public void DeleteAll()
        {
            using (var command = new Npgsql.NpgsqlCommand("DELETE FROM localized_category_text"))
                PerformCommand(command);
        }

        /// <summary>
        /// Inserts a new localized category text
        /// </summary>
        /// <param name="categoryId">The category id</param>
        /// <param name="type">The text type</param>
        /// <param name="language">The language</param>
        /// <param name="text">The text</param>
        public void Insert(int categoryId, String type, String language, String text)
        {
            using (var command = new Npgsql.NpgsqlCommand("INSERT INTO localized_category_text(localized_category_text_id, category_id, type, language, text) VALUES " +
                "(nextval('localized_category_text_id_sequence'), :category_id, :type, :language, :text)"))
            {
                command.Parameters.AddWithValue("category_id", categoryId);
                command.Parameters.AddWithValue("type", type);
                command.Parameters.AddWithValue("language", language);
                command.Parameters.AddWithValue("text", text);

                PerformCommand(command);
            }
        }
    }
}
